const { savePageHtml } = require("./byplaywright");
const { JSDOM } = require("jsdom");
const { Readability } = require("@mozilla/readability");
const fs = require("fs");
async function getArticle(url) {
  const html = await savePageHtml(url, "page.html");
  const doc = new JSDOM(html, { url });
  const reader = new Readability(doc.window.document);
  const article = reader.parse();
  return article;
}

// test
getArticle("https://www.hbgyl.com.cn/#/index").then((article) => {
  //   console.log(article);
  fs.writeFileSync("article.json", article);
  console.log(`Article saved to article.html`);
});

module.exports = {
  getArticle,
};
